
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/timer.h>
#include <linux/slab.h>
#include <asm/cacheflush.h>

MODULE_AUTHOR("mdy");
MODULE_DESCRIPTION("demo");
MODULE_LICENSE("GPL");

static int __init virt_to_phys_demo_init(void)
{
    {
        void* vaddr = kmalloc(1234, GFP_KERNEL);
        unsigned long paddr = virt_to_phys(vaddr);
        printk("viraddr = %px, phyaddr = %lx, diff = %lx\n", vaddr, paddr,
            (unsigned long)vaddr - paddr);
    }
    {
        void* vaddr = (void*)0xffff900000000000;
        unsigned long paddr = virt_to_phys(vaddr);
        printk("viraddr = %px, phyaddr = %lx, diff = %lx\n", vaddr, paddr,
            (unsigned long)vaddr - paddr);
    }
    {
        void* vaddr = (void*)0x00400000;
        unsigned long paddr = virt_to_phys(vaddr);
        printk("viraddr = %px, phyaddr = %lx, diff = %lx\n", vaddr, paddr,
            (unsigned long)vaddr - paddr);
    }
    {
        void* vaddr = (void*)0x123456789abc;
        unsigned long paddr = virt_to_phys(vaddr);
        printk("viraddr = %px, phyaddr = %lx, diff = %lx\n", vaddr, paddr,
            (unsigned long)vaddr - paddr);
    }

    return 0;
}

static void __exit virt_to_phys_demo_exit(void)
{
    return;
}
 
module_init(virt_to_phys_demo_init);
module_exit(virt_to_phys_demo_exit);

